#include "PlotSetting.h"

//set the general style optioins
void SetSgStyle(){
	//No Canvas Border
	gStyle->SetCanvasBorderMode(0);
	gStyle->SetCanvasBorderSize(0);
	//White BG
	gStyle->SetCanvasColor(10);
	//Format for axes
	gStyle->SetLabelFont(22,"xyz");
	gStyle->SetLabelSize(0.06,"xyz");
	gStyle->SetLabelOffset(0.01,"xyz");
	gStyle->SetNdivisions(510,"xyz");
	gStyle->SetTitleFont(22,"xyz");
	gStyle->SetTitleColor(1,"xyz");
	gStyle->SetTitleSize(0.06,"xyz");
	gStyle->SetTitleOffset(0.91);
	gStyle->SetTitleYOffset(1.1);
	//No pad borders
	gStyle->SetPadBorderMode(0);
	gStyle->SetPadBorderSize(0);
	//White BG
	gStyle->SetPadColor(10);
	//Margins for labels etc.
	gStyle->SetPadLeftMargin(0.15);
	gStyle->SetPadBottomMargin(0.15);
	gStyle->SetPadRightMargin(0.05);
	gStyle->SetPadTopMargin(0.06);
	//No error bars in x direnction
	gStyle->SetErrorX(0);
	//Format legend
	gStyle->SetLegendBorderSize(0);
	gStyle->SetLegendFont(22);
	gStyle->SetFillStyle(0);
}

void txtN(Double_t x0, Double_t y0, TH1 *h, std::string sName, Double_t sizeTxt){
	h->SetStats(0);
	TLatex *ltx= new TLatex();
	ltx->SetNDC(1);
	ltx->SetTextColor(h->GetLineColor());
	ltx->SetTextFont(22);
	ltx->SetTextSize(sizeTxt);
	ltx->DrawLatex(x0,y0,Form(sName.c_str(),h->GetEntries()));
	gPad->Modified();
	gPad->Update();
}

TH1F * newTH1F(std::string name, Double_t binw, Double_t LowBin, Double_t HighBin, Bool_t MevTitle, Int_t iMode){
	Int_t nbin=TMath::Nint((HighBin-LowBin)/binw);
	HighBin=binw*nbin+LowBin;
	TH1F *h=new TH1F(name.c_str(),"",nbin,LowBin,HighBin);
	if(MevTitle) h->GetYaxis()->SetTitle(Form("Events / (%.0fMeV/c^{2})",h->GetBinWidth(1)*1000));
	h->SetMinimum(0.0);
	h->GetYaxis()->SetTitleOffset(1.1);
	if(iMode>=0 && iMode<14){
		Int_t iMarker[]={20,21,24,25,28,29,30,27,3,5,2,26,22,23};
		Int_t iColor[]={2,4,6,9,1,50,40,31,41,35,44,38,47,12};
		h->SetMarkerStyle(iMarker[iMode]);
		h->SetMarkerColor(iColor[iMode]);
		h->SetLineColor(iColor[iMode]);
	}
	return h;

}


void LineX1(Double_t atX, Int_t iColor, Int_t iStyle, Double_t iWidth){
	gPad->Modified();
	gPad->Update();
	TLine *l1 = new TLine(atX, gPad->GetUymin(),atX,gPad->GetUymax());
	l1->SetLineColor(iColor);
	l1->SetLineStyle(iStyle);
	l1->SetLineWidth(iWidth);
	l1->Draw();
}


